package com.springcloud.configclient.order80.controller;

import com.springcloud.configclient.commons.entities.CommonResult;
import com.springcloud.configclient.commons.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {
    public static final String PAYMENT_URL="http://localhost:8001";

    @Autowired
    public RestTemplate restTemplate;
    @GetMapping(value = "/consumer/payment/add")
    public CommonResult<Payment> add(Payment payment){
        System.out.println(payment.toString());
        System.out.println("--------consumer add-------");
      return   restTemplate.postForObject(PAYMENT_URL+"/payment/add", payment, CommonResult.class);
    }

    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommonResult<Payment> get(@PathVariable("id") long id){
        System.out.println("-------consumer  get-----");
        return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id, CommonResult.class);
    }


}
